import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lcapp/api/interface/user_api.dart';
import 'package:lcapp/api/request/response_data.dart';
import 'package:lcapp/data/user_data_entity.dart';
import 'package:lcapp/model/toast/toast.dart';
import 'package:lcapp/widget/asr_cache_image.dart';

class FansFollowItem extends StatefulWidget {
  final UserDataEntity entity;
  const FansFollowItem({Key? key, required this.entity}) : super(key: key);

  @override
  _FansFollowItemState createState() => _FansFollowItemState();
}

class _FansFollowItemState extends State<FansFollowItem> {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(bottom: 20.w),
      child: Row(
        children: [
          Container(
            width: 100.w,
            height: 100.w,
            child: Stack(
              children: [
                Center(
                  child: Container(
                    width: 100.w,
                    height: 100.w,
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(100.w)
                    ),
                  ),
                ),
                Center(
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(90.w),
                    child: ASRCacheImage(
                      width: 90.w,
                      height: 90.w,
                      fit: BoxFit.cover,
                      image: widget.entity.img!,
                    ),
                  ),
                ),
              ],
            ),
          ),
          SizedBox(width:30.w),
          Expanded(child: Container(
            height: 100.w,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Expanded(child:  Row(
                  children: [
                    Expanded(child: Text('${widget.entity.name}',style: TextStyle(
                        color: Color(0xff1A051D),
                        fontSize: 32.sp,
                        fontWeight: FontWeight.w600
                    ),)),
                    GestureDetector(
                      onTap: ()async{
                        showLoading();
                        ResponseData res = await UserAPI.followUser(widget.entity.id!);
                        hideLoading();
                        if(res.code==200){
                          setState(() {
                            if(widget.entity.attentionState==1){
                              widget.entity.attentionState=0;
                            }else{
                              widget.entity.attentionState=1;
                            }
                          });
                        }
                      },
                      child: Container(
                        width: 140.w,
                        height: 60.w,
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(60.w),
                            gradient: LinearGradient(
                              colors: widget.entity.attentionState==1?[ Color(0xffE4E4E4),Color(0xffE4E4E4)]: [
                                Color(0xffFF633B),
                                Color(0xffFE4830),
                              ],
                              begin: Alignment.topCenter,
                              end: Alignment.bottomCenter,
                            )),
                        child: Text(widget.entity.attentionState==1?'取消关注':'关注',style: TextStyle(
                            color: Colors.white,
                            fontSize: 26.sp
                        ),),
                      ),
                    )
                  ],
                ),),
                Container(
                  height: 1,
                  color: Color(0xffE9E8E9),
                ),
              ],
            ),
          ),),
        ],
      ),
    );
  }
}
